<template>
	<view :class="[BackGround]" :style="[{'font-weight':Style,'font-family':Font,height:100 + '%',minHeight:height + 'px'}]">
		<cu-custom bgColor="bg-gradual-blue" isBack="true">
			<view slot="backText">返回</view>
			<view slot="content">员工产量报表</view>
		</cu-custom>
		<sear-ch :placeholder="placeholder" @clean="clean" @input="input" @remove="remove" :message="message"></sear-ch>
		<screen-view ref="screen" @formSubmit="formSubmit" :column="column" :searchisShow="false"
		 :isShow="false" :startbefore="dateleft" @checkboxChange="checkboxChange"></screen-view>
		<z-table :tableData="deliverplanyield" :stickSide="false" :showSelect="false" :showBottomSum="false" :columns="finaleColumnsyield"
		 @onSort="doSort" @onSelect="tableSelect" :bottom="180"></z-table>
		<!-- #ifdef APP-PLUS -->
		<view class="table-fixed" @tap="switchP">
			<image :class="[imgclass]" src="/static/images/phoneicon.png" mode="aspectFill"></image>
		</view>
		<!-- #endif -->
		<button class="cu-btn bg-gradual-blue lg shadow tb-flex cu-btn-new fixed_Export" @tap="Export">导出</button>
	</view>
</template>

<script>
	import SearCh from "@/colorui/components/search.nvue";
	import ScreenView from '@/colorui/components/ScreenView.vue'
	import zTable from "@/colorui/components/z-table.vue";
	import utils from '@/static/js/utils.filter.js';
	import {
		mapGetters
	} from "vuex";
	import {
		inputSearch,
		viewTable,
		tableFixed
	} from "@/mixin/mixin.js"
	import {
		getSelect
	} from "@/service/selectList.js"
	import {
		generateExcel
	} from "@/service/insert.js"
	export default {
		mixins: [viewTable, inputSearch, tableFixed],
		data() {
			return {
				placeholder: "员工姓名",
				height: this.screenHeight,
				message: '筛选',
				dateleft: global.startbefore,
				dateright: global.dateright,
				searchView: "LUSERNAME",
				searchCondition: [{
					name: '姓名',
					code: 'LUSERNAME',
					checked: true
				}, ],
				deliverplanyield: [],
				column: [{
						name: '台号',
						value: '台号',
						checked: true
					},
					{
						name: '班组',
						value: '班组',
						checked: true
					},
					{
						name: '姓名',
						value: '姓名',
						checked: true
					},
					{
						name: '班次',
						value: '班次',
						checked: true
					}
				]
			}
		},
		computed: {
			...mapGetters(["Style", 'Font', 'BackGround', 'BackGroundBox'])
		},
		components: {
			SearCh,
			ScreenView,
			zTable,
		},
		onResize() {
			uni.getSystemInfo({
				success: function(res) {
					if (res.windowWidth > res.windowHeight) {
						console.log('横屏');
					} else {
						console.log('竖屏');
					}
				}
			});
		},
		onLoad() {
			const fn = (a, b) => a.filter(item => b.includes(item.title))
			this.list = fn(this.finaleColumnsfive, ['台号', '班组', '姓名', '班次', ])
			this.deliverplan = this.deliverplanfive
			function getNextDay(d){
			    d = new Date(d);
			    d = +d + 1000*60*60*24;
			    d = new Date(d);
			    //return d;
			    //格式化
				let y = d.getMonth()+1
				let t = d.getDate()
			    return d.getFullYear()+"-" + ( y < 10 ? '0' + y : y) + '-' + (t < 10 ? '0' + t : t)
			}
			this.dateright = getNextDay(this.dateright); 
			this.getSelect()
		},
		methods: {
			formSubmit(e) {
				this.dateleft = e.picker1
				this.dateright = e.picker2
				this.getSelect()
			},
			getSelect() {
				getSelect('7023','','',{
					"LBEGINDATE":this.dateleft,
					"LENDDATE":this.dateright,
					"LUSERCODE":""
				}).then(res => {
					if(res.code == 1) {
						res.data.forEach((value,index) => {
							var thisTime = value.LBEGINDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
							value.LBEGINDATE = utils.timeTodate('Y/m/d H:i:s', new Date(thisTime).getTime() + 8 * 3600 * 1000)
							var thisTime = value.LENDDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
							value.LENDDATE = utils.timeTodate('Y/m/d H:i:s', new Date(thisTime).getTime() + 8 * 3600 * 1000)
							var thisTime = value.LTIMESTAMP.replace("T", " ").substring(0, 19).replace(/-/g, '/');
							value.LTIMESTAMP = utils.timeTodate('Y/m/d H:i:s', new Date(thisTime).getTime() + 8 * 3600 * 1000)
						})
						this.deliverplanyield = res.data
						this.deliverplan = res.data
					}
				})
			},
			checkboxChange(e) {
				(function(a, b) {
					a.filter(function(item) {
						if (b.includes(item.title)) {
							item.isShow = true
						} else {
							item.isShow = false
						}
					})
				})(this.list, e)
			},
			Export() {
				if(this.deliverplanyield.length > 0) {
					let mylist = []
					this.deliverplanyield.forEach((value,index) => {
						if(value['isShow'] == true) {
							mylist.push(value)
						}
					})
					generateExcel('CLExcelPojo',mylist).then(res => {
						if(res.code == 1) {
							plus.runtime.openURL(`http://60.173.239.156:8443/image/UserImage/${res.data}`);
						} else {
							uni.showToast({
								title:'导出失败',
								icon:'none'
							})
						}
					})
				} else {
					uni.showToast({
						title:'暂无数据无法导出',
						icon:'none'
					})
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.fixed_Export {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
}
</style>
